package com.module.user.ui.setting

import android.view.View
import com.common.app.base.AppPictureSelectionActivity
import com.common.app.core.RouterHub
import com.common.app.data.bean.BaseCityModel
import com.common.app.data.bean.KeyPre
import com.common.app.helper.RouterHelper
import com.common.app.utls.HeadTitleUtils
import com.common.base.app.extras.setOnClickListener
import com.common.base.app.extras.startActivity
import com.common.base.utils.*
import com.module.user.R
import com.module.user.databinding.UserActivitySettingBinding
import com.module.user.ui.goalSetting.GoalSettingActivity

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2025/7/4
 * <p>
 * 描述：设置页面
 * <p>
 * 修订历史：
 */
class SettingActivity : AppPictureSelectionActivity<UserActivitySettingBinding, SettingViewModel>(),
    View.OnClickListener {

    override fun getViewModel(): Class<SettingViewModel> = SettingViewModel::class.java

    override fun getViewContentBinding() = UserActivitySettingBinding.inflate(layoutInflater)

    override fun isShowToolBar(): Boolean = false
    override fun isStatusBarTranslate(): Boolean = true

    private var savedLanguageType = 0

    private val unitSelectDialog :CommonMeteringUnitSelectDialog? by lazy{CommonMeteringUnitSelectDialog(this)}

    override fun initViews() {
        super.initViews()
        StatusBarUtils.setStatusBarHeight(mViewContentBinding.statusView)
        StatusBarUtils.setStatusBarForegroundColor(this, true)

        val headTitleUtils = HeadTitleUtils(this)
        headTitleUtils.setTitle(resources.getString(R.string.ac_setting_title))
        headTitleUtils.setLineStyle(10)
    }

    override fun onResume() {
        super.onResume()
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun initEvents() {
        super.initEvents()
        mViewContentBinding.kvLanguage.setOnClickListener(onClick = this)

        mViewContentBinding.kvUnitLength.setOnClickListener(onClick = this)
        mViewContentBinding.kvUnitWeight.setOnClickListener(onClick = this)
        mViewContentBinding.kvUnitTemperature.setOnClickListener(onClick = this)
        mViewContentBinding.kvGoalSetting.setOnClickListener(onClick = this)

        unitSelectDialog?.setListener(object : CommonMeteringUnitSelectDialog.OnSelectListener{
            override fun onSelectClick(mType:Int, mBean: BaseCityModel) {
                when(mType){
                    1->mViewContentBinding.kvUnitWeight.setValue(mBean.name)
                    2->mViewContentBinding.kvUnitTemperature.setValue(mBean.name)
                    else->mViewContentBinding.kvUnitLength.setValue(mBean.name)
                }
            }
        })
    }

    override fun lazyInitData() {
        super.lazyInitData()

        mViewContentBinding.kvCancelAccount.setValue("${getString(R.string.user_setting_cancel_ac_hint)}${getString(R.string.user_setting_cancel_ac_email)}")

        MultiLanguageUtil.instance?.let {
            savedLanguageType = it.getLanguageType(this)
        }
        when(savedLanguageType){
            LanguageType.LANGUAGE_FOLLOW_SYSTEM-> mViewContentBinding.kvLanguage.setValue(getString(R.string.setting_language_auto))
            LanguageType.LANGUAGE_CHINESE_TRADITIONAL-> mViewContentBinding.kvLanguage.setValue(getString(R.string.setting_traditional_chinese))
            LanguageType.LANGUAGE_EN->  mViewContentBinding.kvLanguage.setValue(getString(R.string.setting_language_english))
            LanguageType.LANGUAGE_CHINESE_SIMPLIFIED->  mViewContentBinding.kvLanguage.setValue(getString(R.string.setting_simplified_chinese))
            else->mViewContentBinding.kvLanguage.setValue(getString(R.string.setting_simplified_chinese))
        }

        when(SpUtilsManagement.getInt(KeyPre.KEY_METERING_UNIT_WEIGHT)){
            1->mViewContentBinding.kvUnitWeight.setValue(SpUtilsManagement.getString(KeyPre.KEY_METERING_UNIT_WEIGHT_NAME))
            2->mViewContentBinding.kvUnitTemperature.setValue(SpUtilsManagement.getString(KeyPre.KEY_METERING_UNIT_WEIGHT_NAME))
            else->mViewContentBinding.kvUnitLength.setValue(SpUtilsManagement.getString(KeyPre.KEY_METERING_UNIT_WEIGHT_NAME))
        }

        mViewContentBinding.kvUnitWeight.setValue(SpUtilsManagement.getString(KeyPre.KEY_METERING_UNIT_WEIGHT_NAME,getString(R.string.common_metering_unit_weight)))
        mViewContentBinding.kvUnitTemperature.setValue(SpUtilsManagement.getString(KeyPre.KEY_METERING_UNIT_TEM_NAME,getString(R.string.common_metering_unit_tem)))
        mViewContentBinding.kvUnitLength.setValue(SpUtilsManagement.getString(KeyPre.KEY_METERING_UNIT_LENGTH_NAME,getString(R.string.common_metering_unit_length)))
    }

    override fun onClick(v: View?) {
        when (v) {
            mViewContentBinding.kvLanguage -> RouterHelper.navigationPostcard(RouterHub.ROUTER_LANGUAGE_ACTIVITY).navigation()
            mViewContentBinding.kvUnitLength -> unitSelectDialog?.show(0)
            mViewContentBinding.kvUnitWeight -> unitSelectDialog?.show(1)
            mViewContentBinding.kvUnitTemperature ->unitSelectDialog?.show(2)
            mViewContentBinding.kvGoalSetting ->startActivity<GoalSettingActivity>(false)

        }
    }
}